package com.rmy.queue.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rmy.common.annotation.Log;
import com.rmy.common.core.controller.BaseController;
import com.rmy.common.core.domain.AjaxResult;
import com.rmy.common.enums.BusinessType;
import com.rmy.queue.domain.QmsNoticePublish;
import com.rmy.queue.service.IQmsNoticePublishService;
import com.rmy.common.utils.poi.ExcelUtil;
import com.rmy.common.core.page.TableDataInfo;

/**
 * 通知公告Controller
 *
 * @author rmy
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/queue/noticepublish")
public class QmsNoticePublishController extends BaseController
{
    @Autowired
    private IQmsNoticePublishService qmsNoticePublishService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:list')")
    @GetMapping("/list")
    public TableDataInfo list(QmsNoticePublish qmsNoticePublish)
    {
        startPage();
        List<QmsNoticePublish> list = qmsNoticePublishService.selectQmsNoticePublishList(qmsNoticePublish);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QmsNoticePublish qmsNoticePublish)
    {
        List<QmsNoticePublish> list = qmsNoticePublishService.selectQmsNoticePublishList(qmsNoticePublish);
        ExcelUtil<QmsNoticePublish> util = new ExcelUtil<QmsNoticePublish>(QmsNoticePublish.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qmsNoticePublishService.selectQmsNoticePublishById(id));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QmsNoticePublish qmsNoticePublish)
    {
        qmsNoticePublish.setCreateBy(getUsername());
        return toAjax(qmsNoticePublishService.insertQmsNoticePublish(qmsNoticePublish));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QmsNoticePublish qmsNoticePublish)
    {
        qmsNoticePublish.setUpdateBy(getUsername());
        return toAjax(qmsNoticePublishService.updateQmsNoticePublish(qmsNoticePublish));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('queue:noticepublish:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qmsNoticePublishService.deleteQmsNoticePublishByIds(ids));
    }

    /**
     * 发布通知公告
     */
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
	@PostMapping("/publish")
    public AjaxResult publish(@RequestBody QmsNoticePublish qmsNoticePublish) throws IOException {
        return toAjax(qmsNoticePublishService.publishNoticeById(qmsNoticePublish));
    }
}
